/**
 * 	更新供应商交易
 * @author alern2008@gmail.com
 * @系统名称：定制化辅助生成制造系统
 */

package org.ccams.tran;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.ccams.domain.TProvider;
import org.ccams.util.Utils;

public class Tran11123 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// 获得用户录入信息
		//客户信息头
		Integer id 					 =Integer.parseInt(request.getParameter("id"));
        String unitno                =(String) request.getParameter("unitno"); //'供应商编号',    
        String uname                 =(String) request.getParameter("uname"); //'供应商名称',        
        String corporator            =(String) request.getParameter("corporator"); //'法人',              
        String telephone             =(String) request.getParameter("telephone"); //'电话',              
        String mobile                =(String) request.getParameter("mobile"); //'手机',              
        String fax                   =(String) request.getParameter("fax"); //'传真',              
        String email                 =(String) request.getParameter("email"); //'邮箱',              
        String addr                  =(String) request.getParameter("addr"); //'地址',              
        String postcode              =(String) request.getParameter("postcode"); //'邮政编码',          
        String wwwaddr               =(String) request.getParameter("wwwaddr"); //'网址',              
        String linker                =(String) request.getParameter("linker"); //'联系人',            
        String linkertel             =(String) request.getParameter("linkertel"); //'联系人电话',        
        String linkermobile          =(String) request.getParameter("linkermobile"); //'联系人手机',        
        String linkerfax             =(String) request.getParameter("linkerfax"); //'联系人传真',        
        String linkeremail           =(String) request.getParameter("linkeremail"); //'联系人邮箱',        
        String linkerdept            =(String) request.getParameter("linkerdept"); //'联系人所属部门',            
        String ticketaddr            =(String) request.getParameter("ticketaddr"); //'开票地址',          
        String rgefund               =(String) request.getParameter("rgefund"); //'注册资金',          
        String prodvalue             =(String) request.getParameter("prodvalue"); //'产值',              
        String pactno                =(String) request.getParameter("pactno"); //'签定合同编号',      
        String jzdate                =(String) request.getParameter("jzdate"); //'上次结帐日期',      
        String jzperiod              =(String) request.getParameter("jzperiod"); //'结帐周期',          
        String facttel               =(String) request.getParameter("facttel"); //'厂家电话',          
        String factoryaddr           =(String) request.getParameter("factoryaddr"); //'生产厂址',          
        String factlinker            =(String) request.getParameter("factlinker"); //'厂家联系人',        
        String regdate               =(String) request.getParameter("regdate"); //'登记时间',
        String pid                   = (String)request.getParameter("pid");
        String mainmate              =(String) request.getParameter("mainmate"); //'主要产品',          
        String trafficdate           =(String) request.getParameter("trafficdate"); //'运输周期',          
        String servicedate           =(String) request.getParameter("servicedate"); //'质保期',            
        String remark                =(String) request.getParameter("remark");        // '备注',
        String accbank               =(String) request.getParameter("accbank");
        String accuser               =(String) request.getParameter("accuser");
        String accno                 =(String) request.getParameter("accno");
        String acctel                =(String) request.getParameter("acctel");
        String taxno                 =(String) request.getParameter("taxno");
        String paykind               =(String) request.getParameter("paykind");
        String credit                =(String) request.getParameter("credit");        
            pid = (pid != pid) ? pid : "0";
            rgefund = (rgefund != rgefund) ? rgefund : "0";            
            credit = (credit != credit) ? credit : "0"; 
            prodvalue = (prodvalue != prodvalue) ? prodvalue : "0";  
            jzperiod = (jzperiod != jzperiod) ? jzperiod : "0";  
            trafficdate = (trafficdate != trafficdate) ? trafficdate : "0";  
            servicedate = (servicedate != servicedate) ? servicedate : "0";              
             
	        System.out.println("unitno="+unitno);
	        System.out.println("uname="+uname);
	        System.out.println("corporator="+corporator);
	        System.out.println("telephone="+telephone);
	        System.out.println("mobile="+mobile);
	        System.out.println("fax="+fax);
	        System.out.println("email="+email);
	        System.out.println("addr="+addr);
	        System.out.println("postcode="+postcode);
	        System.out.println("wwwaddr="+wwwaddr);
	        System.out.println("linker="+linker);
	        System.out.println("linkertel="+linkertel);
	        System.out.println("linkermobile="+linkermobile);
	        System.out.println("linkerfax="+linkerfax);
	        System.out.println("linkeremail="+linkeremail);
	        System.out.println("linkerdept="+linkerdept);
	        System.out.println("pid="+pid);
	        System.out.println("ticketaddr="+ticketaddr);
	        System.out.println("rgefund="+rgefund);
	        System.out.println("prodvalue="+prodvalue);
	        System.out.println("pactno="+pactno);
	        System.out.println("jzdate="+jzdate);
	        System.out.println("jzperiod="+jzperiod);
	        System.out.println("facttel="+facttel);
	        System.out.println("factoryaddr="+factoryaddr);
	        System.out.println("factlinker="+factlinker);
	        System.out.println("regdate="+regdate);
	        System.out.println("mainmate="+mainmate);
	        System.out.println("trafficdate="+trafficdate);
	        System.out.println("servicedate="+servicedate);
	        System.out.println("remark="+remark);
	        System.out.println("accbank="+accbank);
	        System.out.println("accuser="+accuser);
	        System.out.println("accno="+accno);
	        System.out.println("acctel="+acctel);
	        System.out.println("taxno="+taxno);
	        System.out.println("paykind="+paykind);
	        System.out.println("credit="+credit);	        
		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		boolean success = false;
		String message = "";
		TProvider u = new TProvider();; 
		u.setId(id);
        u.setPid(Integer.parseInt(pid));
        u.setUnitno(unitno);
        u.setUname(uname);
        u.setCorporator(corporator);
        u.setTelephone(telephone);
        u.setMobile(mobile);
        u.setFax(fax);
        u.setEmail(email);
	    u.setAddr(addr);
	    u.setPostcode(postcode);
	    u.setWwwaddr(wwwaddr);
	    u.setLinker(linker);
        u.setLinkertel(linkertel);
        u.setLinkermobile(linkermobile);
        u.setLinkerfax(linkerfax);
        u.setLinkeremail(linkeremail);
        u.setLinkerdept(linkerdept);
        u.setTicketaddr(ticketaddr);
        u.setRgefund(Integer.parseInt(rgefund));
        u.setProdvalue(Integer.parseInt(prodvalue));
        u.setPactno(pactno);
        try{
        	u.setJzdate(Utils.stringToDate(jzdate, "yyyy-MM-dd"));
        }catch(Exception e){}
        u.setJzperiod(Integer.parseInt(jzperiod));
        u.setFacttel(facttel);
        u.setFactoryaddr(factoryaddr);
        u.setFactlinker(factlinker);
        try{ 
        	u.setRegdate(regdate=(regdate==""?null:regdate));
        }catch(Exception e){}
        u.setMainmate(mainmate);
        u.setTrafficdate(Integer.parseInt(trafficdate));
        u.setServicedate(Integer.parseInt(servicedate));
        u.setRemark(remark);
        u.setAccbank(accbank);
        u.setAccuser(accuser);
        u.setAccno(accno);
        u.setAcctel(acctel);
        u.setTaxno(taxno);
        u.setPaykind(paykind);
        u.setCredit(Integer.parseInt(credit));
         
        
     
        int i = getCcamsService().getTproviderDao().updateTProvider(u);
		if (i == 1) {
			success = true;
			message = "供应商	更新成功";
		} else {
			success = false;
			message = "供应商更新失败";
		}
		jsonMap.put("success", success);
		jsonMap.put("message", message);
		json.putAll(jsonMap);
	}
}
